package com.xiaoshuaila.listener;

import com.xiaoshuaila.settings.domain.Dicvalue;
import com.xiaoshuaila.settings.service.Dicservice;
import com.xiaoshuaila.settings.service.DicserviceImpl;
import com.xiaoshuaila.tool.ServiceFactory;
import org.apache.ibatis.io.Resources;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRegistration;
import java.util.*;

public class Sysinitlistener implements ServletContextListener {
    Dicservice dicservice=
            (Dicservice) ServiceFactory.getService(new DicserviceImpl());
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("开始");
        ServletContext application=sce.getServletContext();
        Map<String, List<Dicvalue>>map= dicservice.getall();
        Set<String>set=map.keySet();
        for (String s:set
             ) {
            application.setAttribute(s,map.get(s));
        }
        System.out.println(application.getAttribute("appellation"));
        ResourceBundle resourceBundle=ResourceBundle.getBundle(
                "Stage2Possibility");
        Enumeration<String>e=resourceBundle.getKeys();
        Map<String,String>pmap=new HashMap<>();
        while (e.hasMoreElements()){
            String key=e.nextElement();
            pmap.put(key,resourceBundle.getString(key));
        }
        application.setAttribute("pmap",pmap);
    }
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("结束");
    }
}
